#include <iostream>
#include <functional>
#include"tcp_server.hpp"
#include "log.hpp"
#include "calculate.hpp"
#include "InetAddr.hpp"
#include "socket.hpp"
using namespace socket_ns;
using callback_t = std::function<response(const request &req)>;




void usage(std::string process)
{
    std::cout << "usage: " << process << "server_port" << std::endl;
}
class server
{
public:
    server(callback_t cb) : _cb(cb)
    {
    }
    void server_help(socket_sptr sockptr, InetAddr client_addr)
    {
    }

private:
    callback_t _cb;
};




int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(USAGE_ERROR);
    }
    uint16_t server_port = std::stoi(argv[1]);
    EnableScrean();
    calculate _calculate;
    server callserver(std::bind(&calculate::execute,&_calculate,std::placeholders::_1));
    io_server_t server = std::bind(&server::server_help,&callserver,std::placeholders::_1,std::placeholders::_2);
    std::unique_ptr<tcp_server> tcp_ptr = std::make_unique<tcp_server>(server_port,server);
    tcp_ptr->loop();

    return 0;
}